package com.smcaiot.jfttask.south.convert;

import com.smcaiot.jfttask.domain.Task;
import com.smcaiot.jfttask.south.entity.JftTaskInfo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

/**
 * @Author: cz
 * @Date: 2023/9/27
 * @Description:
 */
@Mapper
public interface JftTaskInfoConvert {
    JftTaskInfoConvert INSTANCE = Mappers.getMapper(JftTaskInfoConvert.class);

    @Mapping(target = "taskId", expression = "java(task.getTaskId().value())")
    @Mapping(target = "cycleLength", expression = "java(task.getTaskCycle().getCycleLength().getCode())")
    @Mapping(target = "cycleType", expression = "java(task.getTaskCycle().getCycleType().getCode())")
    JftTaskInfo from(Task task);

    @Mapping(target = "taskId", expression = "java(TaskId.from(taskInfo.getTaskId()))")
    @Mapping(target = "taskCycle", expression = "java(new com.smcaiot.jfttask.domain.TaskCycle(taskInfo.getCycleLength()))")
    Task to(JftTaskInfo taskInfo);
}
